import wx
import wx.grid
import time


class SimpleGrid(wx.grid.Grid):
    def __init__(self, parent):
        # wx.grid.Grid.__init__(self, parent, -1)
        wx.grid.Grid.__init__(self, parent ,-1 ,size=(600, 210),pos=(50,200))
        self.CreateGrid(9, 5)

        # 设置第index=3列的宽度大小，像素=200
        for num in range(5):
            self.SetColSize(col=num,width=100)

        #设置第index=4行的高度大小，像素=45
        self.SetRowSize(4, 45)


        self.SetColLabelValue(0, "TestItem")
        self.SetColLabelValue(1, "LowLimit")
        self.SetColLabelValue(2, "UpperLimit")
        self.SetColLabelValue(3, "Mearuse")
        self.SetColLabelValue(4, "Result")
        self.SetColLabelValue(5, "Mark")


        self.SetRowLabelValue(0, "9V test")
        self.SetRowLabelValue(1, "-9v Test")
        self.SetRowLabelValue(2, "Check the led")
        self.SetRowLabelValue(3, "Check the AC Current")
        self.SetRowLabelValue(4, "Check the AC Current")
        self.SetRowLabelValue(5, "Read the  DC 12V ")
        self.SetRowLabelValue(6, "Check the AC Current")
        self.SetRowLabelValue(7, "Test end")
        self.SetRowLabelValue(8, "Close all relay")




        self.SetCellValue(0, 0, "Bob")
        self.SetCellValue(0, 1, "Dernier")

        self.SetCellValue(1, 0, "Ryne")
        self.SetCellValue(1, 1, "Sandberg")

        self.SetCellValue(2, 0, "Gary")
        self.SetCellValue(2, 1, "Matthews")

        self.SetCellValue(3, 0, "Leon")
        self.SetCellValue(3, 1, "Durham")

        self.SetCellValue(4, 0, "Keith")
        self.SetCellValue(4, 1, "Moreland")

        self.SetCellValue(5, 0, "Ron")
        self.SetCellValue(5, 1, "Cey")

        self.SetCellValue(6, 0, "Jody")
        self.SetCellValue(6, 1, "Davis")

        self.SetCellValue(7, 0, "Larry")
        self.SetCellValue(7, 1, "Bowa")

        self.SetCellValue(8, 0, "Rick")
        self.SetCellValue(8, 1, "Sutcliffe")


class TestFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, None, 1, "A Grid",size=(800, 600),pos=(1,1))
        panel = wx.Panel(self, -1)

        # self.button.SetDefault()
        grid = SimpleGrid(panel)

        # a = self.SimpleGrid.GetCellValue(1, 0)

        print(grid.GetCellValue(1,1))

        # self.chk1 = wx.CheckBox(panel, -1, "chk1", (10, 10), (40,20))
        # self.chk2 = wx.CheckBox(panel, -1, "chk2", (10, 50), (40, 20))
        # self.chk3 = wx.CheckBox(panel, -1, "chk3", (10, 90), (40, 20))
        # self.chk4 = wx.CheckBox(panel, -1, "chk4", (10, 130),(40, 20))
        # """build the checkbox"""
        #
        # self.chk1.Bind(wx.EVT_CHECKBOX, self.OnCheck1)
        # self.chk2.Bind(wx.EVT_CHECKBOX, self.OnCheck2)
        # self.chk3.Bind(wx.EVT_CHECKBOX, self.OnCheck3)
        # self.chk4.Bind(wx.EVT_CHECKBOX, self.OnCheck4)
        # """bind checkbox click event """

        self.button = wx.Button(panel, -1, "确定", pos=(200, 500))
        self.button1 = wx.Button(panel, -1, "button1", (400, 10), (80, 30))
        self.button2 = wx.Button(panel, -1, "button2", (400, 50), (80, 30))
        self.button3 = wx.Button(panel, -1, "button3", (400, 90), (80, 30))
        self.button4 = wx.Button(panel, -1, "button4", (400, 130), (80, 30))
        """build button"""


        self.button.Bind(wx.EVT_BUTTON, self.buttonclick)
        self.button1.Bind(wx.EVT_BUTTON, self.buttonclick1)
        self.button2.Bind(wx.EVT_BUTTON, self.buttonclick2)
        self.button3.Bind(wx.EVT_BUTTON, self.buttonclick3)
        self.button4.Bind(wx.EVT_BUTTON, self.buttonclick4)
        """bind button click event"""




        self.textbox1 = wx.TextCtrl(panel, -1, "text1", (110, 10), (80,20))
        self.textbox2 = wx.TextCtrl(panel, -1, "text2", (110, 50), (80, 20))
        self.textbox3 = wx.TextCtrl(panel, -1, "text2", (110, 90), (80, 20))
        self.textbox4 = wx.TextCtrl(panel, -1, "text2", (110, 130),(80, 20))
        self.textbox5 = wx.TextCtrl(panel, -1, "", (110, 170), (180, 20))
        """build the text box"""




        """build menu bar"""
        menuBar = wx.MenuBar()
        menu1 = wx.Menu()
        menuBar.Append(menu1, "&File")
        menu1.Append(wx.NewId(), "&Open", "Open")
        menu1.AppendSeparator()
        menu1.Append(wx.NewId(), "&Save", "Save")


        menu2 = wx.Menu()
        menuBar.Append(menu2, "&Edit")

        menu2.Append(wx.NewId(), "&Copy", "Copy in status bar")
        menu2.Append(wx.NewId(), "&Cut", "Cut")
        menu2.Append(wx.NewId(), "Paste", "Paste")
        menu2.AppendSeparator()
        menu2.Append(wx.NewId(), "&Options...", "Display Option")

        self.SetMenuBar(menuBar)

        self.button4.Bind(wx.EVT_MENU_OPEN, self.menurespond)
        """bind button click event"""

        """build tool bar"""
        # statusBar = self.CreateStatusBar()
        # toolBar = self.CreateToolBar()
        # toolBar.AddSimpleTool(wx.NewId(), wx.Bitmap('111.bmp'), "New", "long help for 'New'")
        # toolBar.Realize()


        time.sleep(1)


    def buttonclick(self,sevent):
         self.Destroy()

    def menurespond(self):
        self.textbox1.LabelText = "fileclick"


    def buttonclick1(self,sevent):
        print(self.button1.LabelText)
        mes=self.grid.GetCellValue(1,1)
        print(mes)
        self.textbox5.LabelText="button1"

    def buttonclick2(self, sevent):
        print(self.button2.LabelText)
        self.textbox5.LabelText = "button2"

    def buttonclick3(self, sevent):
        print(self.button3.LabelText)
        self.textbox5.LabelText = "button3"


    def buttonclick4(self, sevent):
        # print(self.button4.LabelText)
        # print(self.button4.Enable())
        self.button4.Disable()
        self.textbox5.LabelText = "disable"
        self.textbox5.Update()
        time.sleep(2)
        self.button4.Enable()
        self.textbox5.LabelText = "enabled"
        self.textbox5.Update()
        time.sleep(2)
        self.textbox5.LabelText = "button4"
        """button click event respond"""



    def OnCheck1(self,sevent):
        print(self.chk1.IsChecked())
        print(self.chk1.GetValue())
        print(self.chk1.GetName())
        print(self.chk1.LabelText)
        """chk1 click event respond"""

    def OnCheck2(self, event):
        print(self.chk2.GetValue())

    def OnCheck3(self, event):
        print(self.chk3.GetValue())

    def OnCheck4(self, event):
         print(self.chk4.GetValue())



# class TestFrame(wx.Frame):
#     def __init__(self, parent):
#         wx.Frame.__init__(self, None)
#         panel = wx.Panel(self)
#         button = wx.Button(panel, -1, u"确定")
#         button.SetDefault()
#         grid = SimpleGrid(panel)
#
#         sizer = wx.BoxSizer(wx.VERTICAL)
#         sizer.Add(grid, 10, wx.EXPAND | wx.ALL, 10)
#         sizer.Add(button, 0, wx.ALIGN_CENTER | wx.BOTTOM, 3)
#         panel.SetSizer(sizer)



if __name__ == '__main__':
    app = wx.App()
    frame = TestFrame(None)
    frame.Show(True)
    app.MainLoop()